package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.netty.util.concurrent.SucceededFuture;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.ValueExp;

/**
 * 护理项目
 * @author yuxiangxun
 * @date 2024/8/21
 * @apiNote
 */
@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController  extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询护理项目
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @ApiOperation("分页查询护理项目")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "名称",required = false) @RequestParam(value = "name",required = false) String name,
            @ApiParam(value = "当前页", required = true) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每天显示条数",required = true ) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态（0:禁用，1:启用）",required = false) @RequestParam(value = "status",required = false) Integer status
    ){
        PageResponse<NursingProjectVo> page = nursingProjectService.getPage(name, pageNum, pageSize, status);
        return success(page);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    /**
     * 回显数据 -> 根据id查询护理项目信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理项目信息")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "护理项目id") @PathVariable("id") Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("编辑护理项目")
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 启用-禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用-禁用护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(
            @ApiParam("主键id") @PathVariable("id") Long id,
            @ApiParam("状态(0:禁用，1:启用)") @PathVariable("status") Integer status
    ){
        nursingProjectService.enableOrDisable(id,status);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理项目信息")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(
            @ApiParam("主键id") @PathVariable("id") Long id
    ){
        //先根据传递过来的id查询VO中有无operationTime字段数据,因为要响应这个字段的数据给前端
        //根据护理项目id查询护理项目信息
        NursingProjectVo byId = nursingProjectService.getById(id);
        //如果没有数据，返回error();
        if(byId == null){
            return ResponseResult.error();
        }
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}
